billing.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { useParams } from 'common'
  2. import { useEffect } from 'react'
  3. import { BillingSettings } from '@/components/interfaces/Organization/BillingSettings/BillingSettings'
  4. import { DefaultLayout } from '@/components/layouts/DefaultLayout'
  5. import OrganizationLayout from '@/components/layouts/OrganizationLayout'
  6. import { UnknownInterface } from '@/components/ui/UnknownInterface'
  7. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  8. import {
  9. ORG_SETTINGS_PANEL_KEYS,
  10. useOrgSettingsPageStateSnapshot,
  11. } from '@/state/organization-settings'
  12. import type { NextPageWithLayout } from '@/types'
  13. const OrgBillingSettings: NextPageWithLayout = () => {
  14. const { panel, slug } = useParams()
  15. const snap = useOrgSettingsPageStateSnapshot()
  16. const showBilling = useIsFeatureEnabled('billing:all')
  17. useEffect(() => {
  18. const allowedValues = ['subscriptionPlan', 'costControl']
  19. if (panel && typeof panel === 'string' && allowedValues.includes(panel)) {
  20. snap.setPanelKey(panel as ORG_SETTINGS_PANEL_KEYS)
  21. document.getElementById('billing-page-top')?.scrollIntoView({ behavior: 'smooth' })
  22. }
  23. // eslint-disable-next-line react-hooks/exhaustive-deps
  24. }, [panel])
  25. if (!showBilling) {
  26. return <UnknownInterface urlBack={`/org/${slug}`} />
  27. }
  28. return <BillingSettings />
  29. }
  30. OrgBillingSettings.getLayout = (page) => (
  31. <DefaultLayout>
  32. <OrganizationLayout title="Billing">{page}</OrganizationLayout>
  33. </DefaultLayout>
  34. )
  35. export default OrgBillingSettings